package flc.ast.activity;

import android.os.Bundle;
import android.text.TextUtils;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.blankj.utilcode.util.NetworkUtils;

import flc.ast.BaseAc;
import flc.ast.R;
import flc.ast.databinding.ActivityTransferInstBinding;
import flc.ast.utils.Content;

public class TransferInstActivity extends BaseAc<ActivityTransferInstBinding> {


    @Override
    protected int onCreate() {
        return R.layout.activity_transfer_inst;
    }

    @Override
    protected void initView() {
        mDataBinding.ivTransferInstBack.setOnClickListener(v -> getOnBackPressedDispatcher().onBackPressed());
    }

    @Override
    protected void initData() {
        mDataBinding.tvIpAddress.setText(getIp() + ":" + Content.Port);
    }

    /**
     * 返回当前设备的ip地址
     *
     * @return
     */
    private String getIp() {
        String ip = NetworkUtils.getIPAddress(true);
        ;
        try {
            String wifiIp = NetworkUtils.getIpAddressByWifi();
            //这里添加这样的处理是因为发现有在小米的Android12系统的手机上通过NetworkUtils.getIPAddress无法
            //获取到局域网地址，而是直接获取到公网地址
            if (!TextUtils.isEmpty(wifiIp) && wifiIp.startsWith("192")) {
                return wifiIp;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ip;
    }

}